package easymall.controller;

import easymall.po.Order;
import easymall.po.OrderItem;
import easymall.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class OrderController {
    @Autowired
    private OrderService orderService;

    @PostMapping("/addOrder")
    public void addOrder(@RequestParam String cartIds,@RequestBody Order order){
        orderService.addOrder(cartIds, order);
    }
    @GetMapping("/findOrderByUserId")
    public List<Order> findOrderByUserId(@RequestParam Integer user_id){
        return orderService.findOrderByUserId(user_id);
    }

    @GetMapping("/getOrderItemsByOrderId")
    public List<OrderItem> getOrderItemsByOrderId(@RequestParam String order_id){
        return orderService.getOrderItemsByOrderId(order_id);
    }

    @GetMapping("/delOrder")
    public void delOrder(@RequestParam String id){
        orderService.delOrder(id);
    }
    @GetMapping("/payOrder")
    public void payOrder(@RequestParam String id){
        orderService.payOrder(id);
    }

    @GetMapping("/confirmOrder")
    public void confirmOrder(@RequestParam String id){
        orderService.confirmOrder(id);
    }

    @PostMapping("/sendOrder")
    public void sendOrder(@RequestBody Order order){
        orderService.sendOrder(order);
    }

    @GetMapping("/getOrdersByPage")
    public List<Order> getOrdersByPage(@RequestParam Integer page) {
        return orderService.getOrdersByPage(page);
    }

    @GetMapping("/totalPage")
    public int totalPage() {
        return orderService.totalPage();
    }

    @GetMapping("/getOrderById")
    public Order getOrderById(@RequestParam String id) {
        return orderService.getOrderById(id);
    }

    @GetMapping("/findAllOrders")
    public List<Order> findAllOrders(){
        return orderService.findAllOrders();
    }
}
